<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet SYSTEM "entities.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="index.xslt"/>

<!--
 | Список тем
 -->
<xsl:template match="forum" mode="content">
<h2>Форум</h2>

<!-- Форма -->
<p><a href="#topic" class="forum_open_form link"><xsl:value-of select="/doc/i18n/forum/form/new_topic"/></a></p>
<div class="forum" style="display: none;">
<form class="forum" action="forspam" method="post">
<p>
    <label for="title"><xsl:value-of select="/doc/i18n/forum/form/title"/>:</label>
    <input name="title" id="title" size="60"/>
</p>
<p>
    <label for="name"><xsl:value-of select="/doc/i18n/forum/form/name"/>:</label>
    <input name="name" id="name" size="20"/>
</p>
<p>
    <label for="email"><xsl:value-of select="/doc/i18n/forum/form/email"/>:</label>
    <input name="email" id="email" size="20"/>
</p>
<p>
    <label for="text"><xsl:value-of select="/doc/i18n/forum/form/message"/>:</label>
    <textarea name="text" id="text" rows="5" cols="60"/>
</p>
<p><input type="submit" value="{/doc/i18n/forum/form/send}" disabled="disabled"/></p>
</form>
</div>
<noscript><xsl:value-of select="/doc/i18n/forum/form/noscript"/></noscript>

<xsl:apply-templates select="pages"/>
<!-- Таблица -->
<table class="forum">
<tr>
    <th><xsl:value-of select="/doc/i18n/forum/topic"/></th>
    <th style="text-align: center;"><xsl:value-of select="/doc/i18n/forum/author"/></th>
    <th style="text-align: center;"><xsl:value-of select="/doc/i18n/forum/childs"/></th>
    <th style="text-align: center;"><xsl:value-of select="/doc/i18n/forum/last"/></th>
</tr>
<xsl:for-each select="item">
<tr>
    <xsl:if test="position() mod 2 = 0">
        <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>
    <td>
        <a href="?id={id}">
            <xsl:value-of select="title"/>
            <xsl:if test="title=''">без заголовка</xsl:if>
        </a>
    </td>
    <td style="text-align: center;"><xsl:apply-templates select="." mode="author"/></td>
    <td style="text-align: center;"><xsl:value-of select="childs"/></td>
    <td style="text-align: center;">
        <xsl:value-of select="last_date"/>
        <xsl:if test="childs &gt; 0">
            <br/>
            <xsl:choose>
                <xsl:when test="last_email!=''">
                    <a href="mailto:{last_email}"><xsl:value-of select="last_name | last_email[../last_name='']"/></a>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="last_name"/>
                    <xsl:if test="last_name=''">
                        <xsl:value-of select="/doc/i18n/forum/anonymous"/>
                    </xsl:if>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </td>
</tr>
</xsl:for-each>
</table>
<xsl:apply-templates select="pages">
    <xsl:with-param name="prev_next" select="true()"/>
</xsl:apply-templates>

</xsl:template>

<!--
 | Список страниц
 -->
<xsl:template match="pages">
<xsl:param name="prev_next" select="false()"/>
<xsl:if test="@count &gt; 1">
<div class="pages">
<xsl:value-of select="/doc/i18n/forum/pages/title"/>:
    <xsl:variable name="page" select="@page"/>
    <xsl:for-each select="page">
        <xsl:text> </xsl:text>
        <span class="num">
            <xsl:choose>
                <xsl:when test=".='..'"><xsl:value-of select="."/></xsl:when>
                <xsl:when test=".=ancestor::pages/@page">
                    <b><xsl:value-of select="."/></b>
                </xsl:when>
                <xsl:otherwise>
                    <a href="?page={.}">
                        <xsl:if test=".=$page"><xsl:attribute name="class">current</xsl:attribute></xsl:if>
                        <xsl:value-of select="."/></a>
                </xsl:otherwise>
            </xsl:choose>
        </span>
    </xsl:for-each>
</div>
<xsl:if test="$prev_next">
<div class="pages_next">
    <xsl:choose>
        <xsl:when test="@page &gt; 1">
            &#8592;&nbsp;<a id="page_prev" href="?page={@page - 1}"><xsl:value-of select="/doc/i18n/forum/pages/prev"/></a>
        </xsl:when>
        <xsl:otherwise>
            <span class="disabled">&#8592;&nbsp;<xsl:value-of select="/doc/i18n/forum/pages/prev"/></span>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
        <xsl:when test="@page &lt; @count">
            <a id="page_next" style="margin-left: 2em;" href="?page={@page + 1}"><xsl:value-of select="/doc/i18n/forum/pages/next"/></a>&nbsp;&#8594;
        </xsl:when>
        <xsl:otherwise>
            <span style="margin-left: 2em;" class="disabled"><xsl:value-of select="/doc/i18n/forum/pages/next"/>&nbsp;&#8594;</span>
        </xsl:otherwise>
    </xsl:choose>
</div>
</xsl:if>
</xsl:if>
</xsl:template>


<!--
 | Вывести имя автора сообщения
 -->
<xsl:template match="*" mode="author">
    <a href="mailto:{email}"><xsl:value-of select="name"/></a>
</xsl:template>
<xsl:template match="*[email='']" mode="author">
    <xsl:value-of select="name"/>
</xsl:template>
<xsl:template match="*[name='']" mode="author">
    <a href="mailto:{email}"><xsl:value-of select="email"/></a>
</xsl:template>
<xsl:template match="*[name='' and email='']" mode="author">
    <xsl:value-of select="/doc/i18n/forum/anonymous"/>
</xsl:template>


<!--
 | Список сообщений темы
 -->
<xsl:template match="topic" mode="content">
<a href="forum.php"><xsl:value-of select="/doc/i18n/forum/back"/></a>
<h2><xsl:value-of select="title"/></h2>

<!-- Сообщения -->
<table class="topic">
<xsl:apply-templates select="." mode="topic"/>
<xsl:apply-templates select="item" mode="topic"/>
</table>

<!-- Форма -->
<p><a href="#topic" class="forum_open_form link"><xsl:value-of select="/doc/i18n/forum/form/reply"/></a></p>
<div class="forum" style="display: none;">
<form class="forum" action="forspam" method="post">
<input type="hidden" name="parent_id" value="{id}"/>
<p>
    <label for="name"><xsl:value-of select="/doc/i18n/forum/form/name"/>:</label>
    <input name="name" id="name" size="20"/>
</p>
<p>
    <label for="email"><xsl:value-of select="/doc/i18n/forum/form/email"/>:</label>
    <input name="email" id="email" size="20"/>
</p>
<p>
    <label for="text"><xsl:value-of select="/doc/i18n/forum/form/message"/>:</label>
    <textarea name="text" id="text" rows="5" cols="60"/>
</p>
<p><input type="submit" value="{/doc/i18n/forum/form/send}" disabled="disabled"/></p>
</form>
</div>
<noscript><xsl:value-of select="/doc/i18n/forum/form/noscript"/></noscript>
</xsl:template>

<!-- Сообщение -->
<xsl:template match="*" mode="topic">
<tr>
    <xsl:if test="(position() mod 2 = 0) or name()!='item'">
        <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>
    <td style="width: 100px;"><xsl:apply-templates select="." mode="author"/></td>
    <td style="width: 600px;">
        <div style="float: right;"><a href="#delete" class="link"><xsl:value-of select="/doc/i18n/forum/delete"/></a></div>
        <div class="message"><xsl:value-of select="text/@html" disable-output-escaping="yes"/></div>
        <hr/>
        <xsl:value-of select="date"/>
    </td>
</tr>
</xsl:template>

</xsl:stylesheet>
